package game.editer.ui;

import hx.events.Event;
import spine.BlendMode;
import hx.display.BlendMode;
import hx.display.ArrayCollection;
import game.editer.AttrEditer.AttrData;

/**
 * DownDropListViewInput修改器
 */
class DownDropListViewInput extends BaseAttributeInput {
	var menu = new DownDropListView();

	public function bindAttrData(attr:AttrData):BaseAttributeInput {
		menu.width = 110;
		var array = attr.attr != null ? attr.attr : attr.attrFunc();
		menu.data = new ArrayCollection(array);
		this.addChild(menu);
		menu.addEventListener(Event.CHANGE, function(e:Event) {
			this.onAttributeChange(this);
		});
		return this;
	}

	override function get_value():Dynamic {
		return menu.selectedItem != null ? menu.selectedItem.data : null;
	}

	override function set_value(value:Dynamic):Dynamic {
		menu.selectedItem = menu.data.source.filter(function(item) {
			return item.data == value;
		})[0];
		if (menu.selectedItem == null) {
			menu.selectedIndex = 0;
		}
		return super.set_value(value);
	}
}
